import java.util.Scanner;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    static int N = 110, n, m;
    static int[][] g = new int[N][N];
    static int[][] f = new int[N][N];
    static int[] dx = {-1, 1, 0, 0};
    static int[] dy = {0, 0, -1, 1};

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        n = in.nextInt();
        m = in.nextInt();
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                g[i][j] = in.nextInt();
            }
        }
        int res = 0;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                res = Math.max(dfs(i, j), res);
            }
        }
        System.out.println(res);
    }

    private static int dfs(int x, int y) {
        if (f[x][y] != 0) {
            return f[x][y];
        }
        int len = 1;
        for (int i = 0; i < 4; i++) {
            int a = dx[i] + x, b = dy[i] + y;
            if (a < 0 || a >= n || b < 0 || b >= m) {
                continue;
            }
            if (g[a][b] >= g[x][y]) {
                continue;
            }
            len = Math.max(len, 1 + dfs(a, b));
        }
        f[x][y] = len;
        return len;
    }
}